//package com.growthserver.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//import java.io.IOException;
//
//@Configuration
//@MapperScan(basePackages = DefaultDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "defaultSessionFactoryBean")
//public class DefaultDataSourceConfig {
//
//
//    static final String PACKAGE = "com.growthserver.mapper.mapper";
//    static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
//
//    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataSourceConfig.class);
//
//    @Value("${spring.default.datasource.url}")
//    private String dbUrl;
//
//    @Value("${spring.default.datasource.username}")
//    private String username;
//
//    @Value("${spring.default.datasource.password}")
//    private String password;
//
//    @Value("${spring.default.datasource.driverClassName}")
//    private String driverClassName;
//
//    @Bean(name = "defaultDataSource")
//    @Primary
//    public DataSource defaultDataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setUrl(dbUrl);
//        dataSource.setDriverClassName(driverClassName);
//        dataSource.setUsername(username);
//        dataSource.setPassword(password);
//        return dataSource;
//    }
//
//    @Bean(name = "defaultSqlSessionTemplate")
//    public SqlSessionTemplate defaultSqlSessionTemplate(
//            @Qualifier("defaultSessionFactoryBean") SqlSessionFactory sqlSessionFactory) {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//    @Bean(name = "defaultTxManager")
//    public DataSourceTransactionManager oracleTxManager(@Qualifier("defaultDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "defaultSessionFactoryBean")
//    public SqlSessionFactory oracleSessionFactoryBean(@Qualifier("defaultDataSource") DataSource dataSource) {
//        try {
//            SqlSessionFactoryBean oracleSessionFactoryBean = new SqlSessionFactoryBean();
//            oracleSessionFactoryBean.setDataSource(dataSource);
//            oracleSessionFactoryBean.setMapperLocations(
//                    new PathMatchingResourcePatternResolver().getResources(DefaultDataSourceConfig.MAPPER_LOCATION));
//            return oracleSessionFactoryBean.getObject();
//        } catch (IOException e) {
//            LOGGER.error("default mybatis resolver mapper*xml is error", e);
//            return null;
//        } catch (Exception e) {
//            LOGGER.error("default mybatis sqlSessionFactory create error", e);
//
//            return null;
//        }
//    }
//
//}
